package cn.wolfcode.trip.base.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
@Getter@Setter
public class Packsack extends BaseDomain{
    //来源
    public static final int SOURCE_BUY = 1;
    public static final int SOURCE_SIGN = 2;
    public static final int SOURCE_ELSE = 3;
    //是否领取
    public static final int ISGET_NO = 1;
    public static final int ISGET_YES = 2;
    //用户
    private Long userId;
    //商品
    private Product product;
    //来源
    private Integer source=SOURCE_BUY;
    //是否领取
    private Integer isget=ISGET_NO;
    //获取时间
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date gaintime;
    //领取时间
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date gettime;
    //关联订单
    private Long orderId;
    public String getIsGetDisplay(){
        if(isget!=null){
            if (isget==ISGET_NO) {
                return "未发货";
            }
            return "已发货";
        }
        return "";
    }
    public String getSourceDisplay(){
        if(source!=null){
            if (source==SOURCE_SIGN) {
                return "签到";
            }else if(source==SOURCE_ELSE) {
                return "其他";
            }
            return "积分商城";
        }
        return "";
    }
    //物品对象签到
    public static Packsack getObject(){
        Packsack packsack = new Packsack();
        packsack.setSource(SOURCE_SIGN);
        packsack.setGaintime(new Date());
        return packsack;
    }
    public static Packsack getObject(OrderList orderList){
        Packsack packsack = new Packsack();
        packsack.setGaintime(new Date());
        packsack.setUserId(orderList.getUser().getId());
        packsack.setProduct(orderList.getProduct());
        packsack.setOrderId(orderList.getId());
        return packsack;
    }
}